package org.colafries.admin.entity.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.colafries.common.enums.Flag;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author colafries
 * @version v1.0
 * @ClassName CustomQueryParamReqVO
 * @Description
 * @date Created in 2024/4/22
 **/
@EqualsAndHashCode(callSuper = true)
@Data
public class CustomQueryReqVO extends ColafriesBaseVO {

    @ApiModelProperty(value = "模型id", dataType = "integer")
    private Integer modelId;

//    @NotNull(message = "模型code不能为空")
    @ApiModelProperty(value = "模型code", dataType = "string", required = true)
    private String modelCode;

    @ApiModelProperty(value = "查询参数")
    private CustomQueryParam queryParam;

    @ApiModelProperty(value = "查询配置")
    @NotNull(message = "查询配置不能为空")
    @Valid
    private QueryConfig queryConfig;

    @ApiModelProperty(value = "查询用户id", dataType = "integer")
    private Integer queryUserId;

    @ApiModelProperty(value = "自定义查询参数备注", dataType = "string")
    private String remark;

    /**
     * 模型查询参数
     */
    @Data
    public static class CustomQueryParam {
        @ApiModelProperty(value = "维度Hash值列表")
        private List<String> dimensions;
        @ApiModelProperty(value = "度量Hash值列表")
        private List<String> measures;
        @ApiModelProperty(value = "查询条件")
        private List<Condition> conditions;
        @ApiModelProperty(value = "查询结果筛选条件")
        private List<Filter> filters;
        @ApiModelProperty(value = "排序")
        private List<Sort> sorts;
    }

    /**
     * 查询条件
     */
    @Data
    public static class Condition {
        @ApiModelProperty(value = "配置列id")
        private Integer id;
        @ApiModelProperty(value = "字段hash值")
        private String fieldHash;
        @ApiModelProperty(value = "运算符 between,in,=,>= ... ...")
        private String operator;
        @ApiModelProperty(value = "筛选值")
        private String value;
    }

    /**
     * 自定义查询结果集筛选条件
     */
    @Data
    public static class Filter {
        @ApiModelProperty(value = "字段hash值")
        private String fieldHash;
        @ApiModelProperty(value = "运算符 between,in,=,>= ... ...")
        private String operator;
        @ApiModelProperty(value = "筛选值")
        private String value;
    }

    /**
     * 排序
     */
    @Data
    public static class Sort {
        @ApiModelProperty(value = "排序字段hash值")
        private String sortFieldHash;
        @ApiModelProperty(value = "排序类型 asc desc")
        private String sortType;
    }

    /**
     * 数据脱敏配置
     */
    @Data
    public static class Fuzzy {

    }

    @Data
    public static class QueryConfig{
        @ApiModelProperty(value = "columns 返回标识")
        @NotNull(message = "Columns返回标识不能为空")
        private Flag columnsReturnFlag;

        @ApiModelProperty(value = "customQuerySql 返回标识")
        @NotNull(message = "CustomQuerySql返回标识不能为空")
        private Flag sqlReturnFlag;

        @ApiModelProperty(value = "分页标识")
        @NotNull(message = "分页标识不能为空")
        private Flag pageFlag;

        @ApiModelProperty(value = "查询结果行数")
        private Integer limit;
    }
}
